<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    #box{
        display: flex;
    }
    .box1{
        width: 100px;
        height: 100px;
        background-color: aqua;
        margin-right: 20px;
    }
</style>
<body>
    <button onclick="goto()">点击div变成红色</button>
    <div id="box">
        <div class="box1"></div>
        <div class="box1"></div>
        <div class="box1"></div>
    </div>
</body>
<script>
    var hh=document.getElementById('box').getElementsByClassName('box1')
    function goto(){
        for(var i=0;i<hh.length;i++){
            hh[i].style.backgroundColor='red'
        }
    }
</script>
</html>